package com.road.vast.springboot;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskQuery;

import java.util.List;

/**
 * @Author 郭泽鹏
 * @Date 2020/6/27 23:20
 * @Version 1.0
 * @Description
 */
public class AssigneeSetNull {
    public static void main(String[] args) {
        //创建ProcessEngine对象
        ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();

        //创建TaskService对象
        TaskService taskService = defaultProcessEngine.getTaskService();

        TaskQuery taskQuery = taskService.createTaskQuery();

        //任务id
        String taskId = "112502";
        //候选人名字
        String candidate_user = "bb0";

        //检验candidate_user是否是taskId的任务负责人，如果是才可以归还组任务
        taskQuery.taskId(taskId).taskAssignee(candidate_user);

        List<Task> list = taskQuery.list();

        if (list != null){
            //设置为null，归还组任务
            for (Task task : list) {
                taskService.setAssignee(task.getId(), null);
                System.out.println("任务负责人：" + candidate_user + "归还组任务：" + task.getId());
            }
        }
    }
}
